local asstes = {
    Asset("ANIM", "anim/ds_rabbit_basic.zip"),
    Asset("ANIM", "anim/rabbit_build.zip"),
    Asset("ANIM", "anim/beard_monster.zip"),
    Asset("ANIM", "anim/rabbit_winter_build.zip"),
    Asset("SOUND", "sound/rabbit.fsb"),
	Asset("INV_IMAGE", "beard_monster"),
	Asset("INV_IMAGE", "rabbit"),
	Asset("INV_IMAGE", "rabbit_winter"),
}

local brain = require("brains/clownrabbitbrain")

SetSharedLootTable("clownrabbit",
{
    {"glommerfuel",  1.0},
    {"glommerfuel",  1.0},
})

local rabbitsounds =
{
    scream = "dontstarve/rabbit/scream",
    hurt = "dontstarve/rabbit/scream_short",
}

local MUST_TAGS = { "_combat" }
local CANT_TAGS = { "INLIMBO", "playerghost", "witch", "witchfriend" }
local function Boom(inst)
    local x, y, z = inst.Transform:GetWorldPosition()
    SpawnPrefab("waterballoon_splash").Transform:SetPosition(x, y, z)
    inst.components.wateryprotection:SpreadProtection(inst)

    local ents = TheSim:FindEntities(x, y, z, 4, MUST_TAGS, CANT_TAGS)
    for i, v in ipairs(ents) do
        if v:IsValid() and v.components.combat then
            v.components.combat:GetAttacked(inst, 0, nil, nil, {
                ["planar"] = 10
            })
        end
    end

    inst.components.lootdropper:DropLoot()
end

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddSoundEmitter()
    inst.entity:AddDynamicShadow()
    inst.entity:AddNetwork()

    MakeCharacterPhysics(inst, 1, 0.5)

    inst.DynamicShadow:SetSize(1, .75)
    inst.Transform:SetFourFaced()

    inst.AnimState:SetBank("rabbit")
    inst.AnimState:SetBuild("rabbit_build")
    inst.AnimState:PlayAnimation("idle")

    inst:AddTag("animal")
    inst:AddTag("prey")
    inst:AddTag("rabbit")
    inst:AddTag("smallcreature")
    inst:AddTag("canbetrapped")
    inst:AddTag("cattoy")
    inst:AddTag("catfood")
    inst:AddTag("stunnedbybomb")
    inst:AddTag("witchfriend")
    inst:AddTag("walpurgisnight_friend")

    MakeFeedableSmallLivestockPristine(inst)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst.sounds = rabbitsounds

    inst.force_onwenthome_message = true

    inst:AddComponent("follower")

    inst:AddComponent("inspectable")

    inst:AddComponent("locomotor") -- locomotor must be constructed before the stategraph
    inst.components.locomotor.runspeed = TUNING.RABBIT_RUN_SPEED

    inst:AddComponent("drownable")

    inst:AddComponent("health")
    inst.components.health:SetMaxHealth(TUNING.RABBIT_HEALTH)

    inst:AddComponent("lootdropper")
    inst.components.lootdropper:SetChanceLootTable("clownrabbit")

    inst:AddComponent("wateryprotection")
    inst.components.wateryprotection.extinguishheatpercent = TUNING.WATERBALLOON_EXTINGUISH_HEAT_PERCENT
    inst.components.wateryprotection.temperaturereduction = TUNING.WATERBALLOON_TEMP_REDUCTION
    inst.components.wateryprotection.witherprotectiontime = TUNING.WATERBALLOON_PROTECTION_TIME
    inst.components.wateryprotection.addwetness = TUNING.CLOWNRABBIT_ADD_WETNESS

    inst:SetStateGraph("SGrabbit")
    inst:SetBrain(brain)

    MakeHauntablePanic(inst)

    inst:ListenForEvent("onwenthome", Boom)

    return inst
end

return Prefab("clownrabbit", fn, asstes)
